//
//  ByApiHome.m
//  recordworktool_ios
//
//  Created by mc on 2018/1/4.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByApiHome.h"

@implementation ByApiHome

+ (void)recordOverseerIndex:(ByNetModel *)model
                    success:(void(^)(ByNetBaseResult *result))success
                    failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    
    if (model.mobile) {
        [dictionary setObject:model.mobile forKey:@"mobile"];
    }
    static NSString *apiType = @"By_JgbRecord_overseerIndex";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeArray
     apiVerson:apiVersion
        params:dictionary
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           NSLog(@"工头 首页 responseObject = %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"添加成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           if(success){
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure){
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
           
       }];
}

+ (void)recordWorkerIndex:(ByNetModel *)model
                  success:(void(^)(ByNetBaseResult *result))success
                  failure:(void(^)(ByNetBaseResult *result))failure{
    
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    
    if (model.mobile) {
        [dictionary setObject:model.mobile forKey:@"mobile"];
    }
    static NSString *apiType = @"By_JgbRecord_workerIndex";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeArray
     apiVerson:apiVersion
        params:dictionary
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           NSLog(@"工人 首页 responseObject =%@", responseObject);
           
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"添加成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           if(success){
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           NSLog(@"error = %@",error);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure){
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
           
       }];
    
    
}


@end
